//
//  ToolView.m
//  HXSDK
//
//  Created by dllo on 16/8/17.
//  Copyright © 2016年 zty. All rights reserved.
//

#import "ToolView.h"
@interface ToolView ()

/**语音*/
@property (nonatomic, strong) UIButton *voiceButton;
/**添加*/
@property (nonatomic, strong) UIButton *addButton;

/**发送*/
@property (nonatomic, strong) UIButton *sendButton;
/**判断*/
@property (nonatomic, assign) BOOL result;
@property (nonatomic, assign) BOOL isSuccess;


@end
@implementation ToolView

-(instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        //添加子控件
        self.voiceButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_voiceButton];
        [_voiceButton addTarget:self action:@selector(voiceAction) forControlEvents:UIControlEventTouchUpInside];
        [_voiceButton setTitle:@"语音" forState:UIControlStateNormal];
        
        self.addButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_addButton];
         [_addButton addTarget:self action:@selector(addAction) forControlEvents:UIControlEventTouchUpInside];
        [_addButton setTitle:@"+" forState:UIControlStateNormal];
        
        self.sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_sendButton];
         [_sendButton addTarget:self action:@selector(sendAction) forControlEvents:UIControlEventTouchUpInside];
        
        self.field = [[UITextView alloc] init];
        
        _field.keyboardAppearance = UIKeyboardAppearanceDark;
        _field.returnKeyType = UIReturnKeyDone;
        //清空 return
        [self addSubview:_field];
        self.result = YES;
        self.isSuccess = YES;
        self.messageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_messageBtn];
      
        [_messageBtn setTitle:@"发送" forState:UIControlStateNormal];
        
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    _voiceButton.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame) * 0.2, CGRectGetHeight(self.frame));
    _addButton.frame = CGRectMake(CGRectGetWidth(self.frame) * 0.9, 0, CGRectGetWidth(self.frame) * 0.1, CGRectGetHeight(self.frame));
    _field.frame = CGRectMake(CGRectGetWidth(self.frame) * 0.2, 20, CGRectGetWidth(self.frame) * 0.6, CGRectGetHeight(self.frame) * 0.5);
    _messageBtn.frame = CGRectMake(CGRectGetWidth(self.frame) * 0.8, 0, CGRectGetWidth(self.frame) * 0.1, CGRectGetHeight(self.frame));
    
    
}

-(void)sendAction{
   
}
-(void)addAction{
    if (_isSuccess) {
        [_addButton setTitle:@"-" forState:UIControlStateNormal];
        
        self.change();
        
    }else{
         [_addButton setTitle:@"+" forState:UIControlStateNormal];
        self.changeAgain();
    }
    _isSuccess = !_isSuccess;
}
-(void)voiceAction{
    if (_result) {
        _sendButton.hidden = NO;
        _field.hidden = YES;
        _sendButton.frame = CGRectMake(CGRectGetWidth(self.frame) * 0.2, 0, CGRectGetWidth(self.frame) * 0.6, CGRectGetHeight(self.frame));
        [_sendButton setTitle:@"长按发送" forState:UIControlStateNormal];
    }else{
        _sendButton.hidden = YES;
        _field.hidden = NO;
        
    }
    _result = !_result;

    
}

@end
